package com.beehoo.dcportal.service.impl;

import java.util.List;

import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.dao.IComplaintDao;
import com.beehoo.dcportal.model.ComplaintBean;
import com.beehoo.dcportal.service.IComplaintServ;
import com.beehoo.dcportal.utils.CommonUtils;

public class ComplaintServImpl implements IComplaintServ {

	private IComplaintDao complaintDao;
	
	public void setComplaintDao(IComplaintDao complaintDao) {
		this.complaintDao = complaintDao;
	}

	@Override
	public void addComplaint(ComplaintBean complaintBean) throws BaseException {
		validateComplaintBean(complaintBean);
		String id = complaintDao.addComplaint(complaintBean);
		if(CommonUtils.nvlToString(id).equals("")){
			throw new BaseException("custom.messages.error.complaint.add.error");
		}
	}

	@Override
	public List<ComplaintBean> queryQueType() throws BaseException {
		return complaintDao.queryQueType();
	}

	@Override
	public List<ComplaintBean> queryServLine() throws BaseException {
		return complaintDao.queryServLine();
	}

	@Override
	public List<ComplaintBean> querySubServLine(String servLineId)
			throws BaseException {
		return complaintDao.querySubServLine(servLineId);
	}
	
	private void validateComplaintBean(ComplaintBean complaintBean)
			throws BaseException {
		if(CommonUtils.nvlToString(complaintBean.getQueAuthor()).equals("")){
			throw new BaseException("custom.messages.error.complaint.author.empty");
		}
		if(CommonUtils.nvlToString(complaintBean.getAuthorPhone()).equals("")){
			throw new BaseException("custom.messages.error.complaint.author.phone.empty");
		}
		if(CommonUtils.nvlToString(complaintBean.getAuthorIdcard()).equals("")){
			throw new BaseException("custom.messages.error.complaint.author.idcard.empty");
		}
		if(CommonUtils.nvlToString(complaintBean.getAuthorAddr()).equals("")){
			throw new BaseException("custom.messages.error.complaint.author.addr.empty");
		}
		if(CommonUtils.nvlToString(complaintBean.getQueContent()).equals("")){
			throw new BaseException("custom.messages.error.complaint.que.content.empty");
		}
		if(CommonUtils.nvlToString(complaintBean.getQueAddr()).equals("")){
			throw new BaseException("custom.messages.error.complaint.que.addr.empty");
		}
	}

}
